package Phanso;

import java.text.Format;
public class Phanso {
	public float ts;
	public float ms;
	public Phanso(){
		ts = 0 ;
		ms = 1 ;
	}
	public Phanso(float ts, float ms)
	{
		this.ts = ts;
		this.ms = ms;
	}
	public Boolean KT(float ts, float ms){
		return ms == 1;
	}
    public static Phanso Phanso(int SN) 
    {
        return  new Phanso(SN, 1);
    }
	  public static int UCLN(float a, float b)
      {
          if(b==0)
              return (int)a;
          else
              return UCLN(b, a%b);
      }
	  public void Reduce(Phanso p){
		  int uoc =  UCLN(Math.abs(p.ts),Math.abs(p.ms));
		  float ts1 = p.ts/uoc;
		  float ms1 = p.ms/uoc;
		  System.out.print("\n"+ts1 + "/"+ ms1);
		  
	  }
	  public void Reciprocal(Phanso a){
		 // a.ToString();
		   Phanso p = new Phanso();
		if(a.ts!= 0)
			    p = new Phanso(a.ms,a.ts);
		  Reduce(p);
	  }
	  public void Add(Phanso p1, Phanso p2){
		  Phanso kq;
          if (p1.ms != p2.ms)
          {
              kq = new Phanso(p1.ts * p2.ms + p2.ts * p1.ms, p1.ms * p2.ms);
          }
          else
              kq = new Phanso(p1.ts + p2.ts, p1.ms);
         Reduce(kq);
          
      }
	  public void Subtract(Phanso p1, Phanso p2){
		  Phanso kq;
          if (p1.ms != p2.ms)
          {
              kq = new Phanso(p1.ts * p2.ms - p2.ts * p1.ms, p1.ms * p2.ms);
          }
          else
              kq = new Phanso(p1.ts - p2.ts, p1.ms);
         Reduce(kq);
          
      }
	  public void Multiply(Phanso p1, Phanso p2){
		  Phanso kq = new Phanso(p1.ts * p2.ts, p1.ms*p2.ms);
		  Reduce(kq);
	  }
	  public void Divide(Phanso p1, Phanso p2){
		  Phanso kq;
		  if(p2.ts == 0)  
			  {
			  System.out.print("khong the chia cho khong");
			  kq = null;
			  }
		  else 
			  kq = new Phanso(p1.ts * p2.ms,p2.ts*p1.ms);
		  Reduce(kq);
	  }
	  
	  public static void main(String[] args)
	  {
		  Phanso a = new Phanso(7,6);
		  a.Reduce(a);
		  Phanso kq = new Phanso();
		  Phanso b = new Phanso(8,4);
		  kq.Add(a,b);
		  kq.Reciprocal(a);
		  kq.Subtract(a, b);
		  kq.Multiply(a, b);
		  kq.Divide(a, b);
	  }
}
interface Comparable{
	void lonhon();
	void bang();
	void nhohon();
}
